/*
 * =====================================================================================
 *
 *       Filename:  string.cpp
 *
 *    Description:  string object 
 *
 *        Version:  1.0
 *        Created:  05/27/2012 09:39:58 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Liu XiaoFei (), 
 *        Company:  
 *
 * =====================================================================================
 */
#include    <string.h>
#include    <vector>
#include    <iostream>
using namespace std;

struct RuleContent
{
    RuleContent()
    {
        std::cout<<"New RuleContent"<<endl;
    }

    RuleContent(int stringlen, string& content)
    {
        if ( (stringlen <= 0) )
        {
            std::cout<<"argument error"<<endl;
        }
        else
        {
            length = stringlen;
            rule = content;
        }
    }

    int length;
    std::string rule;
};

class RuleManger
{
    public:
        RuleManger() {}
        ~RuleManger();

        int SetRule(int , string& );
        int GetRule(int);
        

    private:
        vector<RuleContent> RuleVersion;
};

int RuleManger::SetRule(int ContentLen, string& Content)
{
    RuleContent temp(ContentLen, Content);
    RuleVersion.push_back(temp);

    return 0;
}

int RuleManger::GetRule(int version)
{
    cout<<"size:"<<RuleVersion.size()<<endl;
    cout<<"version:"<<version<<endl;
    int i = version;
    vector<RuleContent>::iterator it;
    it = RuleVersion.begin();
    while(i >= 0)
    {
        it++;
        i--;
    } 
    i = version;
    i++;

    for ( ; it < RuleVersion.end(); ++it, ++i)
    {
        cout<<i<<":"<<(*it).rule<<"[LEN]:"<<(*it).length<<endl;
    }

    return 0;
}

int main(void)
{
    RuleManger* pRuleManager = new RuleManger();

    int datalen = strlen("Hello0");
    string data("Hello0", strlen("Hello0"));
    pRuleManager->SetRule(datalen, data);
    data = string("Hello1");
    pRuleManager->SetRule(datalen, data);
    data = string("Hello2");
    pRuleManager->SetRule(datalen, data);
    data = string("Hello3");
    pRuleManager->SetRule(datalen, data);
    data = string("Hello4");
    pRuleManager->SetRule(datalen, data);
    data = string("Hello5");
    pRuleManager->SetRule(datalen, data);
    data = string("Hello6");
    pRuleManager->SetRule(datalen, data);
    pRuleManager->GetRule(0);

    return 0;
}
